import enum


class TaskStatus(enum.IntEnum):
    start_dialog = 0
    do = 1
    win_dialog = 2
    fail_dialog = 3
    win_over = 4
    fail_over = 5


class BaseTask:
    def __init__(self, begin_dialog, win_dialog, fail_dialog):
        self.begin_dialog = begin_dialog
        self.win_dialog = win_dialog
        self.fail_dialog = fail_dialog
        self.task_status = TaskStatus.start_dialog

    def do_self_task(self, key_down, key_list):
        """
        派生类需要重写方法
        :param key_down:
        :param key_list:
        :return:
        """
        pass

    def do_task(self, key_down, key_list):
        if key_down:
            if self.task_status == TaskStatus.start_dialog:
                self.begin_dialog.next_text()
                if self.begin_dialog.is_finish():
                    self.task_status = TaskStatus.do
            elif self.task_status == TaskStatus.win_dialog:
                self.win_dialog.next_text()
                if self.win_dialog.is_finish():
                    self.task_status = TaskStatus.win_over
            elif self.task_status == TaskStatus.fail_dialog:
                self.fail_dialog.next_text()
                if self.fail_dialog.is_finish():
                    self.task_status = TaskStatus.fail_over
        if self.task_status == TaskStatus.do:
            self.do_self_task(key_down, key_list)

    def get_state(self):
        return self.task_status

    def draw_task(self, current_surface, x, y):
        pass

    def draw(self, current_surface, x, y):
        if self.task_status == TaskStatus.win_over or \
                self.task_status == TaskStatus.fail_over:
            return
        elif self.task_status == TaskStatus.start_dialog:
            self.begin_dialog.draw(current_surface)
        elif self.task_status == TaskStatus.win_dialog:
            self.win_dialog.draw(current_surface)
        elif self.task_status == TaskStatus.fail_dialog:
            self.fail_dialog.draw(current_surface)
        self.draw_task(current_surface, x, y)
